import React, { useReducer, useEffect } from "react";
import "./register.css"
import { initState, reducer, actions } from "./register";
import {reqRegister} from "../../request/api"
const Register = (props) => {
    const [state, dispatch] = useReducer(reducer, initState);

    //进来页面
    useEffect(() => {
        
    },[]);
    let req=()=>{
        // 注册请求
        reqRegister(state.user).then(res => {
            if (res.data.code === 200) {
                //跳转页面
                props.history.push("/login")
            }
        })
    }

    return (
        <div className="register">
            <ul>
                <li>手机号：<input type="text" value={state.phone} onChange={(e) => dispatch(actions.changeUser("phone", e.target.value))} /></li>
                <li>昵称：<input type="text" value={state.nickname} onChange={(e) => dispatch(actions.changeUser("nickname", e.target.value))} /></li>
                <li>密码：<input type="text" value={state.password} onChange={(e) => dispatch(actions.changeUser("password", e.target.value))} /></li>
            </ul>
            <input type="button" value="注册" onClick={() => req()} />
        </div>
    );
};

export default Register;
